Ext.define('AM.view.LeaderRewardView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.leaderRewardView',
		store : 'LeaderRewardStore',
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'), 
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"    //"SINGLE"/"SIMPLE"/"MULTI"
	        
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
        xtype: 'pagingtoolbar',
        dock: 'bottom',
        store : 'LeaderRewardStore',
        displayInfo: true 
    }],
		columns: [	
			        //{text: '序号', xtype: 'rownumberer',width:50,align:'center'},
		{text: '序号',  xtype: 'rownumberer',width:50,align:'center',tdCls:'background-color: #8EE5EE;'},
			        { text: 'ID', dataIndex: 'id', width:0,align:'center'},
			        { text: '姓名', dataIndex: 'name', width:180,align:'center'},
			        { text: '奖金', dataIndex: 'finace', width:180,align:'center'},
			        { text: '日期', dataIndex: 'date', width:180,align:'center'}
			        
			     ],
			   tbar: [
					  { xtype : "numberfield",
						fieldLabel: '请输入奖金',
						labelWidth:80,
					    name: 'finace',
					    minValue:0,
					    id:'searchLeadfinace'
					    
					  },
					  { xtype : "datefield",
						fieldLabel: '日期',
						labelWidth:35,
					    name: 'searchdate',
						format:'Y-m',
						id:'Leadfiancedate',
						listeners:{   
							select:function(field, value){
								         
										 try{ 
										 var rewar;
										 Ext.Ajax.request({
												url : 'departmentFinaceAction_Leadfinace',
											    async : false,
												success : function(response, options) {
													var re =Ext.JSON.decode(response.responseText);
													rewar=re.rewad;
												},
												failure : function() {
													Ext.MessageBox.alert("提示", "本月无计算奖金！");
												},
												params : {
													searchdate:Ext.util.Format.date(this.value, 'Y-m')
												}
											});	
											 var parent=Ext.getCmp('searchLeadfinace');
											 parent.reset();
											 parent.setValue(rewar);													 
										 }
										 catch(ex){
											 Ext.MessageBox.alert("错误","数据加载失败。");
										 }
									}
							}
					  },
					  { xtype: 'button', text: '查询奖金',handler:searchLeadFinace,icon : 'Ext/restful/images/find.png'
					  },
					  { xtype: 'button', text: '计算奖金',handler:countLeadFinace,icon : 'Ext/restful/images/add.png'
					  },
					  { xtype: 'button',
			            text: '导出奖金',
			            icon : 'Ext/restful/images/down2.png',
			            margin: '0 0 0 15',
			            handler: function () {
			            
			                 var searchdate = Ext.util.Format.date(Ext.getCmp('Leadfiancedate').getValue(), 'Y-m');
			                 window.location.href ="Exportperformance?searchdate="+searchdate+" ";
			       		 }
					  }
					]
		
})
function countLeadFinace() {
	     var grid=this.ownerCt.ownerCt;
	     var fiance= Ext.getCmp('searchLeadfinace').getValue();
	     var date= Ext.getCmp('Leadfiancedate').getValue();
	     var searchdate= Ext.util.Format.date(date, 'Y-m');
   		 Ext.Ajax.request({
					url : 'departmentFinaceAction_conutLeadFinace',
					success : function() {
						grid.getStore().on('beforeload', function (store, options) {
				          var new_params = {searchdate:searchdate}
				                Ext.apply(store.proxy.extraParams, new_params);
				       });//此处为加载条件
						  grid.getStore().reload();
								},
					failure : function() {
						Ext.MessageBox.alert("提示", "计算奖金失败！");
					},
					params : {
							reward:fiance,
							searchdate:searchdate
					}
		});	
		
}
function searchLeadFinace() {
   		 var grid=this.ownerCt.ownerCt;
   		 var date= Ext.getCmp('Leadfiancedate').getValue();
	     var searchdate= Ext.util.Format.date(date, 'Y-m');
		 grid.getStore().on('beforeload', function (store, options) {
	          var new_params = {searchdate:searchdate}
	                Ext.apply(store.proxy.extraParams, new_params);
	       });//此处为加载条件
			  grid.getStore().reload();				
}